package com.hengda.museumonline.utils;

import android.support.design.widget.TabLayout;
import android.support.v4.view.ViewPager;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.PopupWindow;

import com.hengda.museumonline.R;
import com.hengda.museumonline.adapter.ListAdapter;
import com.hengda.museumonline.entity.ExlistBean;
import com.hengda.museumonline.ui.MainActivity;

import java.util.ArrayList;

/**
 * @author：JFWU on 2016/10/12 18:40
 * @E-mail：jeffy12138@126.com
 */
public class ListUtil {
    private MainActivity mainActivity;
    private TabLayout tabLayout;
    private ViewPager viewPager;
    private PopupWindow mPopWindow;
    ArrayList<View> mPagers;
    private ImageView ivMap;

    public ListUtil(MainActivity mainActivity, ImageView ivMap) {
        this.mainActivity = mainActivity;
        this.ivMap = ivMap;
    }

    public void dismissPop() {
        if (mPopWindow != null && mPopWindow.isShowing()) {
            mPopWindow.dismiss();
        }

    }

    public void showPop() {
        if (mPopWindow != null) {
            mPopWindow.showAsDropDown(ivMap, 0, 20);
        }

    }

    public void getPopup(int id) {

        View contentView = LayoutInflater.from(mainActivity).inflate(R.layout.popup_museum_list, null);
        tabLayout = (TabLayout) contentView.findViewById(R.id.tabs);
        viewPager = (ViewPager) contentView.findViewById(R.id.viewpager);
        mPagers = new ArrayList<>();
        ListItem listItem0 = new ListItem(mainActivity, id, 0);
        ListItem listItem1 = new ListItem(mainActivity, id, 1);
        ListItem listItem2 = new ListItem(mainActivity, id, 2);
        ListItem listItem3 = new ListItem(mainActivity, id, 3);
        ListItem listItem4 = new ListItem(mainActivity, id, 4);
        RecyclerView recyclerView0 = (RecyclerView) View.inflate(mainActivity, R.layout.fragment_display, null);
        recyclerView0.setLayoutManager(new LinearLayoutManager(recyclerView0.getContext()));
        //  recyclerView0.setAdapter(new MuseumAdapter(getContext(),exlistBean));
        RecyclerView recyclerView1 = (RecyclerView) View.inflate(mainActivity, R.layout.fragment_display, null);
        recyclerView1.setLayoutManager(new LinearLayoutManager(recyclerView1.getContext()));
        // recyclerView1.setAdapter(new MuseumAdapter(getContext(), id, 1));

        RecyclerView recyclerView2 = (RecyclerView) View.inflate(mainActivity, R.layout.fragment_display, null);
        recyclerView2.setLayoutManager(new LinearLayoutManager(recyclerView2.getContext()));
        //  recyclerView2.setAdapter(new MuseumAdapter(getContext(), id, 2));

        RecyclerView recyclerView3 = (RecyclerView) View.inflate(mainActivity, R.layout.fragment_display, null);
        recyclerView3.setLayoutManager(new LinearLayoutManager(recyclerView3.getContext()));
        // recyclerView3.setAdapter(new MuseumAdapter(getContext(), id, 3));

        RecyclerView recyclerView4 = (RecyclerView) View.inflate(mainActivity, R.layout.fragment_display, null);
        recyclerView4.setLayoutManager(new LinearLayoutManager(recyclerView4.getContext()));
        //  recyclerView4.setAdapter(new MuseumAdapter(getContext(), id, 0));

        mPagers.add(listItem0.recyclerView);
        mPagers.add(listItem1.recyclerView);
        mPagers.add(listItem2.recyclerView);
        mPagers.add(listItem3.recyclerView);
        mPagers.add(listItem4.recyclerView);
        viewPager.setAdapter(new ListAdapter(mPagers));
        tabLayout.setupWithViewPager(viewPager);
        tabLayout.getTabAt(0).setText("最热");
        tabLayout.getTabAt(1).setText("即将展出");
        tabLayout.getTabAt(2).setText("正在展出");
        tabLayout.getTabAt(3).setText("已结束");
        tabLayout.getTabAt(4).setText("活动");
        mPopWindow = new PopupWindow(contentView);
        mPopWindow.setWidth(ViewGroup.LayoutParams.FILL_PARENT);
        mPopWindow.setHeight(ViewGroup.LayoutParams.WRAP_CONTENT);

    }


}
